package models;

import javax.persistence.Entity;

import org.apache.commons.lang.builder.HashCodeBuilder;

import play.data.validation.Required;
import play.db.jpa.Model;

@Entity
public class Library extends Model implements Comparable<Library>{

	@Required
	public String name;
	
	@Override
	public String toString() {
		return name;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(id).toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Library other = (Library) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public int compareTo(Library o) {
		if (o.name == null){
			return 1;
		}
		if (name == null){
			return -1;
		}
		
		return name.compareTo(o.name);
	}
}
